import type { ID, IDS, PageQuery, PageResult } from '#/api/common';

import { requestClient } from '#/api/request';

export interface SysConfig {
  id: number;
  configName: string;
  configKey: string;
  configValue: string;
  status: string;
  remark: string;
  createTime: string;
}

enum Api {
  configInfoByKey = '/common/config/configKey',
  configList = '/common/config/page',
  root = '/common/config',
}

/**
 * 系统参数分页列表
 * @param params 请求参数
 * @returns 列表
 */
export function configList(params?: PageQuery) {
  return requestClient.get<PageResult<SysConfig>>(Api.configList, { params });
}

export function configInfo(configId: ID) {
  return requestClient.get<SysConfig>(`${Api.root}/${configId}`);
}

/**
 * 更新系统配置
 * @param data 参数
 */
export function configUpdate(data: Partial<SysConfig>) {
  return requestClient.put(Api.root, data);
}

/**
 * 新增系统配置
 * @param data 参数
 */
export function configAdd(data: Partial<SysConfig>) {
  return requestClient.post(Api.root, data);
}

/**
 * 删除配置
 * @param configIds ids
 */
export function configRemove(configIds: IDS) {
  return requestClient.delete(`${Api.root}/${configIds}`);
}

/**
 * 获取配置信息
 * @param configKey configKey
 * @returns value
 */
export function configInfoByKey(configKey: string) {
  return requestClient.get<string>(`${Api.configInfoByKey}/${configKey}`);
}
